package com.sitechasia.webx.components.xtable.cell;

import org.extremecomponents.table.bean.Column;
import org.extremecomponents.table.cell.Cell;
import org.extremecomponents.table.core.TableModel;
import org.extremecomponents.table.view.html.ColumnBuilder;
import org.extremecomponents.util.HtmlBuilder;

public class TitleStringCell implements Cell {
	public String getHtmlDisplay(TableModel model, Column column) {
		ColumnBuilder columnBuilder = new ColumnBuilder(column);
		columnBuilder.tdStart();
		columnBuilder.tdBody(getCellValue(model, column));
		columnBuilder.tdEnd();
		return columnBuilder.toString();
	}

	public String getExportDisplay(TableModel model, Column column) {
		return "";
	}

	/**
	 * 截取过长字段，在鼠标移动到时显示提示
	 */
	protected String getCellValue(TableModel model, Column column) {
		String value = column.getValueAsString();
		if (value.length() > 5) {
			value = value.substring(0, 4) + "...";
		}
		HtmlBuilder build = new HtmlBuilder();
		build.append(value);
		return build.toString();
	}
}
